<template>
  <div>
    <el-form ref="querForm" size="mini" inline="true" model="querForm">
      <el-form-item label="openid">
        <el-input
          v-model="querForm.openid"
          placeholder="请输入用户openid"
        ></el-input>
      </el-form-item>

      <el-form-item label="">
        <el-button type="primary" @click="chaxun">查询</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="tableData" style="width: 100%">
      <el-table-column prop="id" label="id" width="100"> </el-table-column>
      <el-table-column prop="openid" label="openid" align="center" width="500">
      </el-table-column>

      <el-table-column prop="headimageurl" label="头像"  width="200">
        <template slot-scope="{ row }">
          <el-avatar
            shape="square"
            size="large"
            :src="row.headimageurl"
          ></el-avatar>
        </template>
      </el-table-column>

      <el-table-column prop="nickname" label="昵称" width="200">
      </el-table-column>

      <el-table-column
        prop="registratime"
        label="注册时间"
        align="center"
      >
      </el-table-column>
    </el-table>

    <el-pagination
      class="el-pagination"
      background
      layout="prev, pager, next"
      @current-change="changePage"
      :page-size="querForm.pagesize"
      :total="total"
    >
    </el-pagination>
  </div>
</template>

<script>
import { list, getuserlistlength, cx } from "@/api/user";

export default {
  name: "list-index",
  data() {
    return {
      query: "",
      tableData: [],
      open: false,
      form: {},
      title: "",

      querForm: {
        page: 1,
        pagesize: 9,
        openid: "",
      },
      total: 50,
      loading: true,
    };
  },

  created() {
    this.loadData();
  },
  methods: {
    loadData() {
      setTimeout(() => {
        this.loading = false;
      }, 400);
      list(this.querForm).then((resp) => {
        this.tableData = resp;
      });

      this.getuserlistlength();
    },

    //获取总数据条数
    getuserlistlength() {
      getuserlistlength().then((resp) => {
        this.total = resp;
      });
    },

    //查询

    chaxun() {
      console.log(this.querForm.openid);
      this.querForm.page = 1;
      cx(this.querForm).then((resp) => {
        this.tableData = resp;
      });
    },

    changePage(page) {
      this.querForm.page = page;
      this.loadData();
    },
  },
};
</script>

<style scoped>
.el-pagination {
  position: absolute;
  top: 850px;
}
</style>